package cn.usian.controller;

import cn.usian.pojo.User;
import cn.usian.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController// 只能相应字符串 所以服务消费者调用feign必须用string接收
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;


    @Value("${user.name}")
    private String name;

    @GetMapping("{id}")
    public User findById(@PathVariable Long id) {
        System.out.println(name);
        return userService.findById(id);
    }

    @GetMapping("findPage")
    public Page<User> findPage(@RequestParam(required = true, defaultValue = "1") Integer pageIndex, String name) {
        Page<User> page = userService.findPage(pageIndex, name);
        return page;
    }

    @GetMapping("del")
    public void del(Integer id) {
        userService.del(id);
    }

    @PostMapping("add")
    public void add(@RequestBody User user) {
        userService.add(user);
    }


}
